﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

// -----------------------------------------------------------------------
// <copyright file="$safeitemrootname$.cs" company="$registeredorganization$">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace MenuGame2DXNA
{
    public class sHighScore : Scene
    {
        private GroupTextEntity grouptext;
        
        private VisibleEntityManager veManager;
        private Game game;
        private Dialog dialog;
        public override void LoadContent(Game _game)
        {

            game = _game;
            base.LoadContent(game);
            veManager = new VisibleEntityManager();
            dialog = new Dialog(game, 600, 400, null);
                  
            veManager.AddObject(dialog);

            Stop();
        }

        private void InitListHS()
        {
            List<Score> ListHS = HighScoreDAL.getListScore();
            grouptext = new GroupTextEntity(game.Content, ListHS.Count * 2);

            

            for (int i = 0; i < ListHS.Count; i++)
            {

                grouptext[2 * i].PositionStart = new Vector2(0, i * 30);

                grouptext[2 * i].Text = ListHS[i].Ten;

                grouptext[2 * i + 1].Text = ListHS[i].Diem.ToString("00000");
                grouptext[2 * i + 1].PositionStart = new Vector2(200, i * 30);
                grouptext[2 * i + 1].Align = TextEntity.Alignment.Right;

            }

            grouptext[0].ColorText = Color.Yellow;
            grouptext[1].ColorText = Color.Yellow;
            grouptext[2].ColorText = Color.Silver;
            grouptext[3].ColorText = Color.Silver;
            grouptext[4].ColorText = Color.Brown;
            grouptext[5].ColorText = Color.Brown;
            grouptext.UpdateRealPosition(new Vector2(200, 125));
            grouptext.TopLeft = new Vector2(-2000, -2000);
            grouptext.SetScale(1.3f);
            
        }


        public override void Update(GameTime gameTime)
        {
            if (!isPlayMusic)
            {
                MusicManager.Play("Title");
                isPlayMusic = true;
            }
            KeyboardState kbState = Keyboard.GetState();
            if (kbState.IsKeyDown(Keys.Escape))
            {
                game.Scene = 0;
                Stop();
            }
            veManager.Update(gameTime,Color.White);
        }


        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);
            veManager.Draw(gameTime,spriteBatch);
        }
        public override void Play()
        {
            InitListHS();
            dialog = new Dialog(game, 600, 400, grouptext, "HIGHSCORES");
            dialog.Appear(54);
            veManager.AddObject(dialog);
            base.Play();
        }
        public override void Stop()
        {
            dialog.DisAppear(1);   
            base.Stop();
        }
    }
}
